find_package(Qt6 QUIET)

if(Qt6_FOUND)
  find_package(Qt6 COMPONENTS Core Widgets Gui Concurrent Network OpenGL PrintSupport Xml Svg REQUIRED)
else()
  find_package(Qt5 COMPONENTS Core Widgets Gui Concurrent Network OpenGL PrintSupport Xml Svg REQUIRED)
endif()




set(SOURCES
scintilla/lexers/LexA68k.cpp
scintilla/lexers/LexAPDL.cpp
scintilla/lexers/LexASY.cpp
scintilla/lexers/LexAU3.cpp
scintilla/lexers/LexAVE.cpp
scintilla/lexers/LexAVS.cpp
scintilla/lexers/LexAbaqus.cpp
scintilla/lexers/LexAda.cpp
scintilla/lexers/LexAsm.cpp
scintilla/lexers/LexAsn1.cpp
scintilla/lexers/LexBaan.cpp
scintilla/lexers/LexBash.cpp
scintilla/lexers/LexBasic.cpp
scintilla/lexers/LexBatch.cpp
scintilla/lexers/LexBibTeX.cpp
scintilla/lexers/LexBullant.cpp
scintilla/lexers/LexCLW.cpp
scintilla/lexers/LexCOBOL.cpp
scintilla/lexers/LexCPP.cpp
scintilla/lexers/LexCSS.cpp
scintilla/lexers/LexCaml.cpp
scintilla/lexers/LexCmake.cpp
scintilla/lexers/LexCoffeeScript.cpp
scintilla/lexers/LexConf.cpp
scintilla/lexers/LexCrontab.cpp
scintilla/lexers/LexCsound.cpp
scintilla/lexers/LexD.cpp
scintilla/lexers/LexDMAP.cpp
scintilla/lexers/LexDMIS.cpp
scintilla/lexers/LexDiff.cpp
scintilla/lexers/LexECL.cpp
scintilla/lexers/LexEDIFACT.cpp
scintilla/lexers/LexEScript.cpp
scintilla/lexers/LexEiffel.cpp
scintilla/lexers/LexErlang.cpp
scintilla/lexers/LexErrorList.cpp
scintilla/lexers/LexFlagship.cpp
scintilla/lexers/LexForth.cpp
scintilla/lexers/LexFortran.cpp
scintilla/lexers/LexGAP.cpp
scintilla/lexers/LexGui4Cli.cpp
scintilla/lexers/LexHTML.cpp
scintilla/lexers/LexHaskell.cpp
scintilla/lexers/LexHex.cpp
scintilla/lexers/LexIndent.cpp
scintilla/lexers/LexInno.cpp
scintilla/lexers/LexJSON.cpp
scintilla/lexers/LexKVIrc.cpp
scintilla/lexers/LexKix.cpp
scintilla/lexers/LexLPeg.cpp
scintilla/lexers/LexLaTeX.cpp
scintilla/lexers/LexLisp.cpp
scintilla/lexers/LexLout.cpp
scintilla/lexers/LexLua.cpp
scintilla/lexers/LexMMIXAL.cpp
scintilla/lexers/LexMPT.cpp
scintilla/lexers/LexMSSQL.cpp
scintilla/lexers/LexMagik.cpp
scintilla/lexers/LexMake.cpp
scintilla/lexers/LexMarkdown.cpp
scintilla/lexers/LexMatlab.cpp
scintilla/lexers/LexMaxima.cpp
scintilla/lexers/LexMetapost.cpp
scintilla/lexers/LexModula.cpp
scintilla/lexers/LexMySQL.cpp
scintilla/lexers/LexNimrod.cpp
scintilla/lexers/LexNsis.cpp
scintilla/lexers/LexNull.cpp
scintilla/lexers/LexOScript.cpp
scintilla/lexers/LexOpal.cpp
scintilla/lexers/LexPB.cpp
scintilla/lexers/LexPLM.cpp
scintilla/lexers/LexPO.cpp
scintilla/lexers/LexPOV.cpp
scintilla/lexers/LexPS.cpp
scintilla/lexers/LexPascal.cpp
scintilla/lexers/LexPerl.cpp
scintilla/lexers/LexPowerPro.cpp
scintilla/lexers/LexPowerShell.cpp
scintilla/lexers/LexProgress.cpp
scintilla/lexers/LexProps.cpp
scintilla/lexers/LexPython.cpp
scintilla/lexers/LexR.cpp
scintilla/lexers/LexRebol.cpp
scintilla/lexers/LexRegistry.cpp
scintilla/lexers/LexRuby.cpp
scintilla/lexers/LexRust.cpp
scintilla/lexers/LexSAS.cpp
scintilla/lexers/LexSML.cpp
scintilla/lexers/LexSQL.cpp
scintilla/lexers/LexSTTXT.cpp
scintilla/lexers/LexScriptol.cpp
scintilla/lexers/LexSmalltalk.cpp
scintilla/lexers/LexSorcus.cpp
scintilla/lexers/LexSpecman.cpp
scintilla/lexers/LexSpice.cpp
scintilla/lexers/LexStata.cpp
scintilla/lexers/LexTACL.cpp
scintilla/lexers/LexTADS3.cpp
scintilla/lexers/LexTAL.cpp
scintilla/lexers/LexTCL.cpp
scintilla/lexers/LexTCMD.cpp
scintilla/lexers/LexTeX.cpp
scintilla/lexers/LexTxt2tags.cpp
scintilla/lexers/LexVB.cpp
scintilla/lexers/LexVHDL.cpp
scintilla/lexers/LexVerilog.cpp
scintilla/lexers/LexVisualProlog.cpp
scintilla/lexers/LexYAML.cpp
scintilla/lexlib/Accessor.cpp
scintilla/lexlib/CharacterCategory.cpp
scintilla/lexlib/CharacterSet.cpp
scintilla/lexlib/DefaultLexer.cpp
scintilla/lexlib/LexerBase.cpp
scintilla/lexlib/LexerModule.cpp
scintilla/lexlib/LexerNoExceptions.cpp
scintilla/lexlib/LexerSimple.cpp
scintilla/lexlib/PropSetSimple.cpp
scintilla/lexlib/StyleContext.cpp
scintilla/lexlib/WordList.cpp
scintilla/src/AutoComplete.cpp
scintilla/src/CallTip.cpp
scintilla/src/CaseConvert.cpp
scintilla/src/CaseFolder.cpp
scintilla/src/Catalogue.cpp
scintilla/src/CellBuffer.cpp
scintilla/src/CharClassify.cpp
scintilla/src/ContractionState.cpp
scintilla/src/DBCS.cpp
scintilla/src/Decoration.cpp
scintilla/src/Document.cpp
scintilla/src/EditModel.cpp
scintilla/src/EditView.cpp
scintilla/src/Editor.cpp
scintilla/src/ExternalLexer.cpp
scintilla/src/Indicator.cpp
scintilla/src/KeyMap.cpp
scintilla/src/LineMarker.cpp
scintilla/src/MarginView.cpp
scintilla/src/PerLine.cpp
scintilla/src/PositionCache.cpp
scintilla/src/RESearch.cpp
scintilla/src/RunStyles.cpp
scintilla/src/ScintillaBase.cpp
scintilla/src/Selection.cpp
scintilla/src/Style.cpp
scintilla/src/UniConversion.cpp
scintilla/src/ViewStyle.cpp
scintilla/src/XPM.cpp
src/InputMethod.cpp
src/ListBoxQt.cpp
src/MacPasteboardMime.cpp
src/PlatQt.cpp
src/SciAccessibility.cpp
src/SciClasses.cpp
src/ScintillaQt.cpp
src/qsciabstractapis.cpp
src/qsciapis.cpp
src/qscicommand.cpp
src/qscicommandset.cpp
src/qscidocument.cpp
src/qscilexer.cpp
src/qscilexerasm.cpp
src/qscilexeravs.cpp
src/qscilexerbash.cpp
src/qscilexerbatch.cpp
src/qscilexercmake.cpp
src/qscilexercoffeescript.cpp
src/qscilexercpp.cpp
src/qscilexercsharp.cpp
src/qscilexercss.cpp
src/qscilexercustom.cpp
src/qscilexerd.cpp
src/qscilexerdiff.cpp
src/qscilexeredifact.cpp
src/qscilexerfortran.cpp
src/qscilexerfortran77.cpp
src/qscilexerhex.cpp
src/qscilexerhtml.cpp
src/qscilexeridl.cpp
src/qscilexerintelhex.cpp
src/qscilexerjava.cpp
src/qscilexerjavascript.cpp
src/qscilexerjson.cpp
src/qscilexerlua.cpp
src/qscilexermakefile.cpp
src/qscilexermarkdown.cpp
src/qscilexermasm.cpp
src/qscilexermatlab.cpp
src/qscilexernasm.cpp
src/qscilexeroctave.cpp
src/qscilexerpascal.cpp
src/qscilexerperl.cpp
src/qscilexerpo.cpp
src/qscilexerpostscript.cpp
src/qscilexerpov.cpp
src/qscilexerproperties.cpp
src/qscilexerpython.cpp
src/qscilexerruby.cpp
src/qscilexerspice.cpp
src/qscilexersql.cpp
src/qscilexersrec.cpp
src/qscilexertcl.cpp
src/qscilexertekhex.cpp
src/qscilexertex.cpp
src/qscilexerverilog.cpp
src/qscilexervhdl.cpp
src/qscilexerxml.cpp
src/qscilexeryaml.cpp
src/qscimacro.cpp
src/qsciprinter.cpp
src/qsciscintilla.cpp
src/qsciscintillabase.cpp
src/qscistyle.cpp
src/qscistyledtext.cpp

src/ListBoxQt.h
src/Qsci/qsciabstractapis.h
src/Qsci/qsciapis.h
src/Qsci/qscicommand.h
src/Qsci/qscicommandset.h
src/Qsci/qscidocument.h
src/Qsci/qsciglobal.h
src/Qsci/qscilexer.h
src/Qsci/qscilexerasm.h
src/Qsci/qscilexeravs.h
src/Qsci/qscilexerbash.h
src/Qsci/qscilexerbatch.h
src/Qsci/qscilexercmake.h
src/Qsci/qscilexercoffeescript.h
src/Qsci/qscilexercpp.h
src/Qsci/qscilexercsharp.h
src/Qsci/qscilexercss.h
src/Qsci/qscilexercustom.h
src/Qsci/qscilexerd.h
src/Qsci/qscilexerdiff.h
src/Qsci/qscilexeredifact.h
src/Qsci/qscilexerfortran.h
src/Qsci/qscilexerfortran77.h
src/Qsci/qscilexerhex.h
src/Qsci/qscilexerhtml.h
src/Qsci/qscilexeridl.h
src/Qsci/qscilexerintelhex.h
src/Qsci/qscilexerjava.h
src/Qsci/qscilexerjavascript.h
src/Qsci/qscilexerjson.h
src/Qsci/qscilexerlua.h
src/Qsci/qscilexermakefile.h
src/Qsci/qscilexermarkdown.h
src/Qsci/qscilexermasm.h
src/Qsci/qscilexermatlab.h
src/Qsci/qscilexernasm.h
src/Qsci/qscilexeroctave.h
src/Qsci/qscilexerpascal.h
src/Qsci/qscilexerperl.h
src/Qsci/qscilexerpo.h
src/Qsci/qscilexerpostscript.h
src/Qsci/qscilexerpov.h
src/Qsci/qscilexerproperties.h
src/Qsci/qscilexerpython.h
src/Qsci/qscilexerruby.h
src/Qsci/qscilexerspice.h
src/Qsci/qscilexersql.h
src/Qsci/qscilexersrec.h
src/Qsci/qscilexertcl.h
src/Qsci/qscilexertekhex.h
src/Qsci/qscilexertex.h
src/Qsci/qscilexerverilog.h
src/Qsci/qscilexervhdl.h
src/Qsci/qscilexerxml.h
src/Qsci/qscilexeryaml.h
src/Qsci/qscimacro.h
src/Qsci/qsciprinter.h
src/Qsci/qsciscintilla.h
src/Qsci/qsciscintillabase.h
src/Qsci/qscistyle.h
src/Qsci/qscistyledtext.h
src/SciAccessibility.h
src/SciClasses.h
src/ScintillaQt.h

)

add_library(QScintilla ${SOURCES} ${RESOURCES}) # Win32 ignored on non-windows
target_include_directories(QScintilla
  PRIVATE
  scintilla/src
  scintilla/include
  scintilla/lexlib
  PUBLIC
  src
)

if(Qt5_FOUND)
  target_link_libraries(QScintilla
  PUBLIC
  Qt5::PrintSupport
  Qt5::Widgets
  Qt5::OpenGL
  Qt5::Xml
  )
else()
  target_link_libraries(QScintilla
  PUBLIC
  Qt::PrintSupport
  Qt::Widgets
  Qt::OpenGL
  Qt::Xml
  )
endif()

target_compile_definitions(QScintilla PRIVATE -DSCINTILLA_QT)
target_compile_definitions(QScintilla PRIVATE -DSCI_LEXER)
target_compile_definitions(QScintilla PRIVATE -DQT)
target_compile_definitions(QScintilla PRIVATE -D_CRT_SECURE_NO_WARNINGS)

# Disable warnings
if(WIN32)
target_compile_options(QScintilla PRIVATE /wd4099 /wd4005 /wd4554 /wd4101 /wd4700 /wd5038 /wd4267 /wd4996)
elseif(${CMAKE_SYSTEM_NAME} MATCHES Linux)
target_compile_options(QScintilla
PRIVATE
-Wno-reorder
-Wno-switch
-Wno-parentheses
-Wno-sign-compare
-Wno-char-subscripts
-Wno-missing-braces
-Wno-strict-overflow
-Wno-misleading-indentation
)
elseif(${CMAKE_SYSTEM_NAME} MATCHES Darwin) # macOS
  # Link to Qt Mac Extras
  if(NOT Qt6_FOUND)
    find_package(Qt5 COMPONENTS MacExtras REQUIRED)
    target_link_libraries(QScintilla
      PUBLIC
      Qt5::MacExtras
      )
  endif()

target_compile_options(QScintilla
PRIVATE
-Wno-absolute-value
-Wno-char-subscripts
-Wno-mismatched-tags
-Wno-missing-braces
-Wno-parentheses
-Wno-reorder
-Wno-sign-compare
-Wno-switch
-Wno-unused-private-field
)
else()
message(FATAL_ERROR "QScintilla is not supported on this platform.")
endif()
